/*
 * ajimber
 *
 */

package vista.ListaInteres;

import vista.*;
import Utilidades.Errores;
import controlador.ListaInteresControlador;
import java.sql.SQLException;
import java.util.*;
import modelo.ListaInteresModelo;
import modelo.entidades.ListaInteres;


public class ListaInteresVistaImp extends AbstractVistaImp<ListaInteresControlador, ListaInteresModelo> implements ListaInteresVista {

    //Atributos propios de Swing
    private ListaInteresTableModel tableModel;
    private ListaInteresVistaInterior panelListaInteres;

    /** Creates new form vehiculoVistaImp */
    public ListaInteresVistaImp() {
        tableModel = ListaInteresTableModel.create();
        initComponents();
        this.panelListaInteres = new ListaInteresVistaInterior(this);
        this.jPanelListaInteres.add(this.panelListaInteres);
    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableListaInteres = new javax.swing.JTable();
        jPanelListaInteres = new javax.swing.JPanel();

        setForeground(new java.awt.Color(255, 204, 204));

        jTableListaInteres.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 51, 255)));
        jTableListaInteres.setForeground(new java.awt.Color(255, 153, 153));
        jTableListaInteres.setModel(tableModel);
        jTableListaInteres.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableListaInteresMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableListaInteres);

        jPanelListaInteres.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelListaInteres.setLayout(new javax.swing.BoxLayout(jPanelListaInteres, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelListaInteres, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelListaInteres, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents





    private void jTableListaInteresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableListaInteresMouseClicked
        ListaInteresTableModel atm = (ListaInteresTableModel) this.jTableListaInteres.getModel();
        ListaInteres listaInteres = atm.getRow(this.jTableListaInteres.getSelectedRow());
        panelListaInteres.setListaInteres(listaInteres);
    }//GEN-LAST:event_jTableListaInteresMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanelListaInteres;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableListaInteres;
    // End of variables declaration//GEN-END:variables

   public void refresh() {
      try {
         tableModel.setListaInteres(getModel().listar()); //cambia el modelo de JTable(TableModel) por medio de una clase que hemos creado (ContactosTableModel)
     } catch (SQLException ex) {
           Errores.mostrarError(ex);
      } catch (Exception ex) {
          Errores.mostrarError(ex);
      }
    }

    protected void fireActualizaListaInteresGesture(String matricula, String fecha , String motivo) {
        List<String> datos = new ArrayList<String>();
        datos.add(matricula);
        datos.add(fecha);
        datos.add(motivo);

        getController().actualizaEntidadGesture(datos);
    }

    protected void fireNuevoListaInteresGesture(String matricula, String fecha , String motivo) {
        List<String> datos = new ArrayList<String>();
        datos.add(matricula);
        datos.add(fecha);
        datos.add(motivo);

        getController().nuevaEntidadGesture(datos);
    }

    protected void fireBorraListaInteresGesture(String matricula) {
        System.out.println(matricula);
        getController().borraEntidadGesture(matricula);
    }
}


